<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Order extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->checkAdmin($this->session->userdata('admin_id'));
        $this->data['controller'] = 'order';
        $this->load->model('Morder');
    }
    
    public function index()
    {
        $this->data['id_active'] = $this->getParamUri(3,2);
        $this->load->library('pagination');
        $config['per_page'] = 20;
        $this->data['page'] = $this->data['pageg'] = $this->getParamUri(3,2);
        $data = $this->Morder->getOrderDB($config['per_page'],$this->getParamUri(3,2));
        $config['base_url'] = base_url($this->uri->segment(1).'/'.$this->uri->segment(2).'/');
        $config['total_rows'] = $data['count'];
        $config['uri_segment'] = 3;
        $config['uri_segment_page'] = $this->getParamUri(3,2);
        $config['suffix'] = '.html';
        $this->pagination->initialize($config);
        
        $this->data['data'] = $data['data'];
        
        $this->data['action'] = 'index';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function detail()
    {
        $id = $this->getParamInt('id');
        $this->data['data'] = $this->Morder->getdetail($id);
        $this->data['action'] = 'detail';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function deleteorder()
    {
        $run = $this->Morder->deleteProductDB($this->session->userdata('username'));
        if($run == 200)
        {
            die('<meta charset="utf-8"><script>alert("Xóa đơn hàng thành công");window.location.href="'.$this->data['baseurl'].'manage/order.html";</script>');
        }
        
    }
    public function infoorder()
    {
        $this->data['data'] = $this->Morder->getInfo();
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        if($this->form_validation->run() === TRUE)
        {
            $this->Morder->addInfo();
            die('<meta charset="utf-8"><script>alert("Cập nhật thành công");window.location.href="'.$this->data['baseurl'].'manage/info-order.html";</script>');
        }
        $this->data['action'] = 'infoorder';
        $this->load->view('temp/layout', $this->data);
    }
}